
#include "iostream"
#include "vector"
#include "unordered_map"
#include "algorithm"
#include "string"
#include "list"
class Solution{
public:
    bool is_zhishu(int n){
        for(int i=2;i*i<=n;i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }

    void handle(std::string &s){
        int max=1;
        for(int i=s.size();i>0;i--){
            for(int off=0;off<s.size()-i+1;off++){
                int a= atoi(s.substr(off,i).c_str());
                if(is_zhishu(a)&&a<10000){
                    if(a>max){
                        max=a;
                    }
//                    return;
                }
            }
        }

        printf("%d\n",max);
    }
};

int main() {
//    bool cur_num= true;
    std::string s;
    while(std::getline(std::cin,s)){
        Solution sol;
        sol.handle(s);
    }
    return 0;
}

